package com.zhaokuner.parentstarter.common;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * 类描述:分页返回
 *
 * @author 赵希坤 zhaoxikun
 * @date 2020/12/14 15:03
 */
public class BaseListVO<T> extends BaseListAO {
    /**
     * 数据总条数
     */
    protected Long total;
    /**
     * 数据列表
     */
    protected List<T> list;

    public BaseListVO() {
    }

    public BaseListVO(BaseListAO ao) {
        super(ao);
    }

    public static <T> BaseListVO<T> newInstance() {
        return new BaseListVO<>();
    }

    public static <T> BaseListVO<T> newInstance(BaseListAO ao) {
        return new BaseListVO<>(ao);
    }

    public BaseListVO<T> page(BaseListAO ao) {
        this.pageFlag = ao.getPageFlag();
        this.pageIndex = ao.getPageIndex();
        this.pageSize = ao.getPageSize();
        return this;
    }

    public BaseListVO<T> data(List<T> list) {
        this.list = list;
        return this;
    }

    /**
     * 添加一条数据
     *
     * @param t
     * @return data
     */
    public List<T> addToList(T t) {
        if (null == list) {
            list = new ArrayList<>();
        }
        list.add(t);
        return list;
    }

    /**
     * 添加列表集合
     *
     * @param c
     * @return data
     */
    public List<T> addAllList(Collection<T> c) {
        if (null == list) {
            list = new ArrayList<>();
        }
        list.addAll(c);
        return list;
    }

    public Long getTotal() {
        return total;
    }

    public void setTotal(Long total) {
        this.total = total;
    }

    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }

    @Override
    public String toString() {
        return "BaseListVO{" +
                "total=" + total +
                ", list=" + list +
                ", pageIndex=" + pageIndex +
                ", pageSize=" + pageSize +
                ", pageFlag='" + pageFlag + '\'' +
                '}';
    }
}
